//package com.liangliang.service;
//
//import org.apache.kafka.common.protocol.types.Field;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.kafka.core.KafkaTemplate;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Service;
//
//import java.util.Random;
//
//@Service
//public class KafkaDataProducerService {
//
//    @Autowired
//    private KafkaTemplate<String, String> kafkaTemplate;
//
//    private static final String TOPIC = "shixuntopicss";
//    private static final String[] PROVINCES_CITIES = {
//        "0,北京,北京",
//        "1,上海,上海",
//        "2,南京,江苏省",
//        "3,广州,广东省",
//        "4,三亚,海南省",
//        "5,武汉,湖北省",
//        "6,长沙,湖南省",
//        "7,西安,陕西省",
//        "8,成都,四川省",
//        "9,哈尔滨,东北省"
//    };
//
//    @Scheduled(fixedRate = 5000)
//    public void sendMessages() {
//        long timestamp = System.currentTimeMillis();
//        int userId = new Random().nextInt(100);
//        int adId = new Random().nextInt(20);
//        String[] provinceCity = PROVINCES_CITIES[new Random().nextInt(PROVINCES_CITIES.length)].split(",");
//        Integer cityId = Integer.parseInt(provinceCity[0]);
//        String province = provinceCity[1];
//        String city = provinceCity[2];
//
//        String message = timestamp + "\t" + userId + "\t" + cityId + "\t" +  province + "\t" + city + "\t" + adId;
//        kafkaTemplate.send(TOPIC, message);
//        System.out.println("Sent message: " + message);
//    }
//}
